package com.tan.androidtest.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * Created by Administrator on 2017/12/4.
 */

public class NetUtil {

    /**
     * 检查是否有网
     *
     * @param context
     * @return true or false
     */
    public static boolean isNetworkAvailable(Context context) {
        ConnectivityManager cm = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        if (cm != null) {
            NetworkInfo n = cm.getActiveNetworkInfo();
            if (n != null)
                return n.isAvailable();
        }

        return false;
    }

}
